package com.example.administrator.radarplusfriendsdemo;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;

import com.example.administrator.radarplusfriendsdemo.been.Info;
import com.example.administrator.radarplusfriendsdemo.custom.RadarPlusFriendView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends Activity {


    @BindView(R.id.rpfv)
    RadarPlusFriendView rpfv;

    private int[] mImgs = {R.drawable.meiv, R.drawable.boy, R.drawable.meiv, R.drawable.boy,
            R.drawable.meiv, R.drawable.boy, R.drawable.meiv, R.drawable.boy};

    private String[] mNames = {"ImmortalZ", "唐马儒", "王尼玛", "张全蛋",
            "蛋花", "王大锤", "叫兽", "哆啦A梦"};

    private ArrayList<Info> mDatas = new ArrayList<>();//存储模拟的用户的信息
    private Context mContext;

    private int mDateLenth = 6;//模拟数据的个数

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initParamsAndValus();

        ButterKnife.bind(this);

        initView();

        initData();
    }

    /**
     * 初始化一些值
     */
    private void initParamsAndValus() {

        mContext = this;

        for (int i = 0; i < mDateLenth; i++) {
            Info info = new Info();
            info.setPortraitId(mImgs[i%8]);
            info.setName(mNames[i%8]);
            if (i == 0 || i == 3 || i == 7) {
                info.setType(Info.TYPE_QING_WO);//请我
            } else if(i == 1 || i == 4 || i == 5){
                info.setType(Info.TYPE_WO_QING);//我请
            }else{
                info.setType(Info.TYPE_NONE);//什么也没有
            }
            mDatas.add(info);
        }
    }

    private void initView() {
        rpfv.setChooseStateListener(mChooseStateListener);
    }

    RadarPlusFriendView.ChooseStateListener mChooseStateListener = new RadarPlusFriendView.ChooseStateListener() {
        @Override
        public void chooseState(int state) {
            if (state == RadarPlusFriendView.TYPE_UN_LIMITED){//不限
                Toast.makeText(mContext, "不限", Toast.LENGTH_SHORT).show();
            }else if(state == RadarPlusFriendView.TYPE_MALE){//男性
                Toast.makeText(mContext, "男性", Toast.LENGTH_SHORT).show();
            }else if(state == RadarPlusFriendView.TYPE_FEMALE){//女性
                Toast.makeText(mContext, "女性", Toast.LENGTH_SHORT).show();
            }
        }
    };

    /**
     * 构造模拟数据，构造8个
     */
    private void initData() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                rpfv.setDatas(mDatas);
            }
        }, 1500);
    }
}
